<template>
	<view class="page" style="background-image:url('/static/images/bg.png');">
		<view class="header" :style="'height:'+HeaderBar+'px;padding-top:'+StatusBar+'px'"></view>
	  <view class="bodyBg">
	    <view class="head" @click="dl">
	      <view class="portrait">
	        <image mode="scaleToFill" :src="avatar"  lazy-load="true"></image>
	      </view>
	      <view class="user">
	        <view class="phone">{{tel}}</view>
	      </view>
	    </view>
	    
	    <!-- <grid :list="gridList" onItemClick="onItemClick"/> -->
			
			<view class="list">
			  <block v-for="(item,index) of gridList" :key="index">
			    <view class="list-item" @click="onItemClick(item.id)" style="background-image:url('/static/images/profile/youjiantou.png');">
			      <view class="item-icon">
			        <image v-if="item.id == 5 || item.id == 6" mode="scaleToFill" :src="item.icon" style="width: 80%; height: 90%; margin-left: 10rpx; box-sizing: border-box;"  lazy-load="true"/>
			        <image v-else mode="scaleToFill" :src="item.icon"  lazy-load="true"/>
			      </view>
			      <view class="item-text">{{item.text}}</view>
			      <!-- <view class="item-action">{{item.action}}</view> -->
			    </view>
			  </block>
			</view>
			
	  </view>
	  <!-- <view class="bodyBg">
		  <button style="height:100rpx; margin-top:50rpx" @click="quit">退出登录</button>
	  </view> -->
	  <view class="height126"></view>
	</view>
</template>

<script>
	import {getServiceTel} from '@/service/profile'
	import {scAppId, baseURL} from '@/service/config'
	export default {
		data() {
			return {
				HeaderBar: getApp().globalData.HeaderBar,
				StatusBar: getApp().globalData.StatusBar,
				avatar: '/static/images/profile/portrait.png',
				userInfo: '',
				gridList: [
					{ 
						id: '1',
						icon: '/static/images/profile/icon_wddd.png',
						text: '我的订单',
						action: '1个待审核订单'
					},
					{
						id: '4',
						icon: '/static/images/profile/icon_yjfk.png',
						text: '意见反馈',
						action: ''
					},
					{
						id: '5',
						icon: '/static/images/profile/icon_lxkf.png',
						text: '联系客服',
						action: ''
					},
					// {
					// 	id: '6',
					// 	icon: '/static/images/profile/icon_lxkf.png',
					// 	text: '购车贷提单',
					// 	action: ''
					// }
				],
				tel:"未登录",
				header:""
			}
		},
		onLoad() {
		},
		onShow(){
			let _this = this;
			uni.getStorage({
				key: "userInfo",
				success(userInfoData){
					let header = {
						'content-type': 'application/x-www-form-urlencoded',
						'Authorization': userInfoData.data.token
					};
					let tel = userInfoData.data.mobile;
					tel = tel.substring(0,3) +'****'+ tel.substring(9);
					_this.userInfo = userInfoData.data;
					_this.tel = tel;
					_this.header = header;
					const prams = {
						"mobile": userInfoData.data.mobile, 
						"siteUserId": userInfoData.data.siteUserId,
					};
				},
				fail(err){
					// _this.dtLogin(15);
				},
				complete(){
					if(_this.userInfo.token==''||_this.userInfo.token==undefined||_this.userInfo.token==null){
						// _this.dtLogin(15);
					}
				}
			})
		},
		methods: {
			/**退出登陆 */
			// quit(){
			// 	uni.clearStorage();
			// },
			/**点击头像，登录 */
			dl(){
				if (this.userInfo.token==''||this.userInfo.token==undefined||this.userInfo.token==null) {
					this.dtLogin(15);
				}
			},
			/**判断是否登录,没有登录调用此方法*/
			dtLogin(param){
				uni.navigateTo({url: "../login/getPhoneNumber?id="+param})
			},
			onItemClick(ev) {
				const thisIdx = ev;
				let _this = this;
				// if(thisIdx == 6) uni.navigateTo({ url: '/pages/chengyongche/index/index' }) // 跳转下单页面-测试使用
				if(_this.userInfo.token==''||_this.userInfo.token==undefined||_this.userInfo.token==null){
					_this.dtLogin(15);
					return
				}
				if(thisIdx == 1) {  // 我的订单
					if(!_this.userInfo.token) {
						_this.dtLogin(151);
					}else {
						uni.navigateTo({ url: '/pages/initial/orderList/orderList?isOrder=1' })
					}
				}else if(thisIdx == 4) {  // 意见反馈
					if(!_this.userInfo.token) {
						_this.dtLogin(154);
					}else {
						uni.navigateTo({ url: '/pages/initial/profileGrid/feedback/feedback' })
					}
				}else if(thisIdx == 5) {
					if(!_this.userInfo.token) {
						_this.dtLogin(155);
					}else {
						_this._getServiceTel(_this.header) // 联系客服
					}
				}
			},
			_getServiceTel(prams,header) {
				getServiceTel(prams,header).then(res => {
					if(res.data.resultCode == "0000") {
						uni.makePhoneCall({ phoneNumber: res.data.data.serviceTel });
					}else {
						uni.hideLoading();
						uni.showModal({
							title: res.data.resultMsg
						});
					}
				}).catch(err => {
					console.log(err);
					uni.hideLoading();
				})
			}
		}
	}
</script>

<style>
	@import url("./profile.css");
	@import url("./grid.css");
</style>
